<?php
session_start();
/*................................................................
 .  Ｅ路联盟　开源程序                                          .
 .  版本: 8.6.6                                                    . 
 .  原作: 16lm (isrn@qq.com)    
 .	MSN:www.16lm.com@hotmail.com
 .  QQ: 446070551                          .
 .  支持: http://www.16lm.com                                   .
................................................................*/
//error_reporting(7);
require_once '../../includes/global.php';
//right($_GET[pid],"../logout.php");
if($_GET[op]=='list')
{
if(isset($_GET[offset]) and isset($_GET[pageline]))
{
$classtest = new tviewpage($prefix.'_rcfg',$_GET[pageline],$_GET[offset]);
//echo "GET";
}
else
{

$offset=0;
$pageline=12;  
$classtest = new tviewpage($prefix.'_rcfg',$pageline,$offset);

//echo "none";
}
/* 设置查询条件
if($_GET[id]!=''){
$condition=" where 1"; 
	if($_GET[id]==0){
$_SESSION[condition]=$condition;
	}
	else
	{
$condition.=" and sortid =".$_GET[id];
$_SESSION[condition]=$condition;
	}
}*/
$classtest->setCondition(" where 1 and del !='1' ORDER BY `id`  DESC  ");

$classtest->setPageQuery('op','list');

$recordset = $classtest->getRecords();
ob_start();
$classtest->showFullFunc();
$nav = ob_get_contents();
ob_end_clean();
$ttt->assign("nav","$nav");


$j = count($recordset);

for($t=0;$t<$j;$t=$t+1){
//$w=Dga('sort',"S_id =".$recordset[$t][typeid]);
$content.="<tr class=\"tbhead\">
      <td width=\"26%\" nowrap style='cursor:hand;' title='".$recordset[$t][intro]."'>".$recordset[$t]['title']."</td>
      <td width=\"11%\" nowrap  >".$recordset[$t]['id']."</td>
      <td width=\"63%\" align=\"center\" nowrap  >
	  〖<a href=\"?op=mod&id=".$recordset[$t][id]."\">编辑</a>〗
	  〖<a href=\"?op=del&id=".$recordset[$t][id]."\">删除</a>〗
	  ".$fu."
	  </td>
    </tr>";
}


$ttt->assign("content",$content);
Ts("mod/right_list.htm");
}
function getallchillrenid($id,$i,$selected)
{
global $db,$sortlist;
$tristr="<font color='#ebebeb' style='line-height:25px;	'>|</font>";
$temp=Dgs('mod'," parentid='".$id."' and t1 =1  and del != 1 and lg like '".$_SESSION['LG']."'");
	if($temp !='')
	{ 
		foreach($temp as $p)
		{	
				
			$qq=Dgs('mod',"parentid='".$p[id]."' and t1 =1  and del != 1 and lg like '".$_SESSION['LG']."'");
			if($i==0){$st="<hr width=80% align=left color='#ebebeb'>";}else{$st='';}
			if($qq!='')
			{	
			$sortlist.=$st.str_repeat('－－',$i)."<font color=red>【".$p['title']."】</font><BR>";
			$j=$i+1;
			getallchillrenid($p[id],$j,$selected);
			}
			else
			{
			$sortlist.=$st.str_repeat('－－',$i)."<font color=red>".$p['title']."</font> <input name=\"rcfg[".$p['id']."]\"  type=\"text\"  value=\"".$selected[$p['id']]."\"><BR>";
			}
		}
	}
}

if($_GET[op]=='add')
{
$ttt->assign("op","insert");
if($id==''){
$_GET[id]='-1';
}
getallchillrenid($_GET[id],0);
$ttt->assign('sortlist',$sortlist);

Ts("mod/rightmodadd.htm");
}

if($_POST[op]=='insert')
{
//Jc('p');
$_POST[id]="";
$_POST['rcfg']=json_encode($_POST['rcfg']);
$_POST['intro']=html_entity_decode(stripslashes($_POST['intro']));
Di("rcfg",$_POST);
Jt("right.php?op=list",'添加成功!(Add seccess!)');
}

if($_POST[op]=='update')
{
foreach($_POST['rcfg'] as $key => $value){
	if($value==''){
	unset($_POST['rcfg'][$key]);
	}
}
/*
Jc($_POST['rcfg']);
exit;
*/
$_POST['rcfg']=json_encode($_POST['rcfg']);
$_POST['intro']=html_entity_decode(stripslashes($_POST['intro']));
Du('rcfg',$_POST,'id',$_POST[id]);
Jt("right.php?op=list",'更新成功！(Update Successful!!)');
}
/**/
if($_GET[op]=='mod')
{
$w=Dga('rcfg',"id =".$_GET[id]);
	foreach($w as $r => $t){
     $ttt->assign($r,$t);
	}
	$w['rcfg']=json_decode($w['rcfg'],true);
	//Jc($w['rcfg']);
getallchillrenid(-1,0,$w['rcfg']);
$ttt->assign('sortlist',$sortlist);
$ttt->assign("op","update");
Ts("mod/rightmodadd.htm");
}

if($_GET[op]=='del')
{
	@$db->query("update `".$prefix."_rcfg` set del='1' WHERE `id` = '".$_GET[id]."'");
	Jt($_SERVER['HTTP_REFERER'],'删除成功！');
}
if($_GET[op]=='deluser')
{
@deletes('user','userid',$_GET[id]);

Jt($_SERVER['HTTP_REFERER'],'删除成功！');
}
if($_GET[op]=='adduser')
{
$ttt->assign("op","insertuser");
Ts("mod/useradd.htm");
}
if($_POST[op]=='insertuser')
{
$p=Dga('user',"username = '".$_POST[username]."'");
if($p!='')
{
Jt($_SERVER['HTTP_REFERER'],'用户名已存在请重新选择！');
}
$_POST[userid]="";
$_POST[password]=md5($_POST[password]);
$_POST[addtime]=date("Y-m-d");
Di("user",$_POST);
Jt("right.php?op=listuser",'添加成功！');
}

if($_GET[op]=='listuser')
{
//print_r($_GET);
//$ttt->assign('kg',$_GET[kg]);
/*if($_GET[kg]=='')
{
$_GET[kg]='-1';
}
*/
if(isset($_GET[offset]) and isset($_GET[pageline]))
{
$classtest = new tviewpage($prefix.'_user',$_GET[pageline],$_GET[offset]);
//echo "GET";
}
else
{

$offset=0;
$pageline=12;  
$classtest = new tviewpage($prefix.'_user',$pageline,$offset);

//echo "none";
}
/* 设置查询条件
if($_GET[id]!=''){
$condition=" where 1"; 
	if($_GET[id]==0){
$_SESSION[condition]=$condition;
	}
	else
	{
$condition.=" and sortid =".$_GET[id];
$_SESSION[condition]=$condition;
	}
}*/
//$classtest->setCondition(" where parentid='".$_GET[kg]."' ORDER BY `id`  DESC  ");

$classtest->setPageQuery('op','listuser');
//$classtest->setPageQuery('kg',$_GET[kg]);

$recordset = $classtest->getRecords();
ob_start();
$classtest->showFullFunc();
$nav = ob_get_contents();
ob_end_clean();
$ttt->assign("nav","$nav");


$j = count($recordset);

for($t=0;$t<$j;$t=$t+1){
$fu="<a href='#' onclick=\"showorhidden(j".$recordset[$t][userid].")\">〖更改密码〗</a></TD>   
  </TR>
    <tbody name='j".$recordset[$t][userid]."' id='j".$recordset[$t][userid]."' style=\"display:none;\">
  <tr><td colspan=7 bgColor=#ffffff ><form method=post op=mod.php name='form".$recordset[$t][userid]."'>
更改密码:<input name='psw' type=text  size=15>
            
<input type=hidden name=op value=upzt>
<input type=hidden name=userid value=".$recordset[$t][userid].">

<input type=submit value=更新>

</td></form>
</tr>
  </tbody>
  ";
//$w=Dga('sort',"S_id =".$recordset[$t][typeid]);
$content.="<tr class=\"tbhead\">
      <td width=\"26%\" nowrap >".$recordset[$t][username]."</td>
      <td width=\"11%\" nowrap  >".$recordset[$t][userid]."</td>
      <td width=\"11%\" nowrap  >".$recordset[$t][addtime]."</td>
      <td width=\"63%\" align=\"center\" nowrap>
	  〖<a href=\"?op=moduser&id=".$recordset[$t][userid]."\">编辑</a>〗
	  〖<a href=\"?op=deluser&id=".$recordset[$t][userid]."\">删除</a>〗
	  〖<a href=\"?op=rightapply&userid=".$recordset[$t][userid]."\">查看权限</a>〗
	  ".$fu."
	  </td>
    </tr>";
}


$ttt->assign("content",$content);
Ts("mod/user_list.htm");
}
if($_POST[op]=='updateuser')
{
//print_r($_POST);
$t[email]=$_POST[email];
$t[info]=$_POST[info];
Du("user",$t,'userid',$_POST[userid]);
Jt("right.php?op=listuser",'更新成功！');
}
/**/
if($_GET[op]=='moduser')
{
$w=Dga('user',"userid =".$_GET[id]);
	foreach($w as $r => $t){
     $ttt->assign($r,$t);
	}
	$ttt->assign("notice","不可更改");
	$ttt->assign("kg","1");
	$ttt->assign("op","updateuser");
	Ts("mod/useradd.htm");
}



if($_GET[op]=='rightapply')
{

$ttt->assign('kg',$_GET[kg]);

Ts("mod/rightaply.htm");
}


if($_GET[op]=='right')
{
//print_r($_GET);
//$ttt->assign('kg',$_GET[kg]);
/*if($_GET[kg]=='')
{
$_GET[kg]='-1';
}
*/
if(isset($_GET[offset]) and isset($_GET[pageline]))
{
$classtest = new tviewpage($prefix.'_user',$_GET[pageline],$_GET[offset]);
//echo "GET";
}
else
{

$offset=0;
$pageline=64;  
$classtest = new tviewpage($prefix.'_user',$pageline,$offset);

//echo "none";
}
/* 设置查询条件
if($_GET[id]!=''){
$condition=" where 1"; 
	if($_GET[id]==0){
$_SESSION[condition]=$condition;
	}
	else
	{
$condition.=" and sortid =".$_GET[id];
$_SESSION[condition]=$condition;
	}
}*/
$classtest->setCondition("where username like '%".$_GET[username]."%'  ORDER BY `userid`  DESC  ");

$classtest->setPageQuery('op','right');
//$classtest->setPageQuery('kg',$_GET[kg]);

$recordset = $classtest->getRecords();
ob_start();
$classtest->showFullFunc();
$nav = ob_get_contents();
ob_end_clean();
$ttt->assign("nav","$nav");


$j = count($recordset);

$content.="<tr bgcolor='ffffff'>";
for($t=0;$t<$j;$t=$t+1){
//$w=Dga('sort',"S_id =".$recordset[$t][typeid]);
if(($t+1)%8==0)
{
 $content.="<td bgcolor='ffffff'><a href=\"?op=rightapply&userid=".$recordset[$t][userid]."\">".$recordset[$t][username]."</a></td></tr><tr bgcolor='ffffff'>";
}
else
{
 $content.="<td bgcolor='ffffff'><a href=\"?op=rightapply&userid=".$recordset[$t][userid]."\">".$recordset[$t][username]."</a></td>";
}

}
   $content.="</tr>";

$ttt->assign("content",$content);
Ts("mod/member.htm");
}
if($_POST[op]=='upzt')
{
pzll();
$ar[password]=md5($_POST[psw]);
Du('user',$ar,'userid',$_POST[userid]);
Jt($_SERVER['HTTP_REFERER'],'修改成功！');

}

?>